<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h2>Criar Usuário</h2>


            <h:form id="form" acceptcharset="utf-8">
                <p:panel styleClass="container_24 clearfix " style="background: none; border: none;"> 
                    <p:growl id="msg" life="3000"/>
                    <p class="subtitle"> Dados Gerais</p>

                    <p:outputLabel value="Nome:" styleClass="grid_3" for="nomeInputText"/>
                    <p:inputText id="nomeInputText" styleClass="grid_18" 
                                  value="#{managerCriarUsuario.usuario.nome}"/>
                    
                    <p:outputLabel value="Curso:" styleClass="grid_3" for="cursoSelectCheckboxMenu" />
                    <div class="grid_8">
                        <p:selectOneMenu id="cursoSelectCheckboxMenu"
                                         value="#{managerCriarUsuario.curso}" 
                                         label="Selecione o curso" filter="true"
                                         filterMatchMode="contains"
                                         required="true"
                                         converter="cursoconverter"
                                         caseSensitive="false" panelStyle="width:220px">
                            <f:selectItem itemLabel="" itemValue="" />
                            <f:selectItems value="#{managerCriarUsuario.cursos}" var="item" 
                                           itemLabel="#{item.codigo.concat(' - ').concat(item.nome)}" itemValue="#{item}" />  
                        </p:selectOneMenu>
                    </div>
                    
                </p:panel> 
                <div class="clear"/>
                
                <p:panel id="loginPanel" styleClass="container_24 clearfix " style="background: none; border: none;">
                    <p class="subtitle"> Dados Login</p>

                    <p:outputLabel value="Login:" styleClass="grid_3" for="loginInputText"/>
                    <p:inputText id="loginInputText" styleClass="grid_10" 
                                 value="#{managerCriarUsuario.usuario.login}">
                        <p:ajax event="blur" update="loginPanel" listener="#{managerCriarUsuario.existLogin()}"/>
                    </p:inputText>
                    <p:outputLabel value="Login já existe" rendered="#{managerCriarUsuario.login}" styleClass="grid_4" style="color: red;"/>
                    <div class="clear"/>

                    <p:outputLabel value="Senha:" styleClass="grid_3" for="senhaPassword"/>
                    <p:password id="senhaPassword" styleClass="grid_10" 
                                value="#{managerCriarUsuario.usuario.senha}" feedback="true"/>
                    <div class="clear"/>

                    <p:outputLabel value="Repetir Senha:" styleClass="grid_3" for="repetirSenhaPassword"/>
                    <p:password id="repetirSenhaPassword" styleClass="grid_10" 
                                value="#{managerCriarUsuario.senha}" feedback="true"/>
                </p:panel>

                <div class="clear"/>
                <p:panel id="adminPanel" styleClass="container_24 clearfix " style="background: none; border: none;">

                    <p class="subtitle"> Administração</p>
                    <br/>
                    <p:outputLabel value="Acesso:" styleClass="grid_3"/>
                    <p:selectCheckboxMenu value="#{managerCriarUsuario.grupoSelecionado}" styleClass="grid_10" converter="grupoconverter" label="Nível de Acesso" >  
                        <f:selectItems value="#{managerCriarUsuario.grupos}" var="g" itemValue="#{g}" />  
                    </p:selectCheckboxMenu> 

                </p:panel> 

                <div class="buttonAction">
                    <p:commandButton value="Salvar" actionListener="#{managerCriarUsuario.salvar()}"
                                     icon="ui-icon-disk" styleClass="ui-priority-primary"
                                     update="@form"  />
                    <p:button value="Cancelar" icon="ui-icon-circle-close"
                              href="indexusuario.xhtml" />
                </div>
            </h:form>

        </ui:define>
    </ui:composition>
</html>